package main

import "github.com/syndtr/goleveldb/leveldb"

type DB struct {
	path string
}

func InitDB() *DB {
	return &DB{
		path: "db",
	}
}
func (server *DB) Get(key []byte) (value []byte, err error) {
	db, err := leveldb.OpenFile(server.path, nil)
	server.PanicError(err)
	defer db.Close()
	data, err := db.Get(key, nil)
	return data, err
}
func (server *DB) Put(key []byte, value []byte) error {
	db, err := leveldb.OpenFile(server.path, nil)
	server.PanicError(err)
	defer db.Close()
	err = db.Put(key, value, nil)
	return err
}

func (server *DB) PanicError(err error) {
	if err != nil {
		panic(err)
	}
}
